<template>
  <div class="app-container">
    <!--    查询对话框-->
    <el-dialog
      :title="title"
      v-model="openSearch"
      :close-on-click-modal="false"
      draggable
      width="420px"
      append-to-body
    >
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        v-show="showSearch"
        label-width="110px"
      >
        <el-col :span="24">
          <el-form-item label="厂商代码" prop="csmCsdm">
            <el-input
              v-model="queryParams.csmCsdm"
              placeholder="请输入厂商代码"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="供货类型" prop="csmType">
            <el-select
              v-model="queryParams.csmType"
              placeholder="请选择供货类型"
              clearable
              size="small"
            >
              <el-option
                v-for="dict in csmTypeOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="厂商名称" prop="csmCsmc">
            <el-input
              v-model="queryParams.csmCsmc"
              placeholder="请输入厂商名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="产品名称" prop="csmCpmc">
            <el-input
              v-model="queryParams.csmCpmc"
              placeholder="请输入产品名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="公司名称" prop="csmGsmc">
            <el-input
              v-model="queryParams.csmGsmc"
              placeholder="请输入公司名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="审核状态" prop="csmZtbz">
            <el-form-item>
              <el-radio-group v-model="queryParams.csmZtbz">
                <el-radio label="1">待审核</el-radio>
                <el-radio label="2">已审核</el-radio>
                <el-radio label="-1">全部</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item
            style="display: flex; margin-top: 20px; justify-content: flex-end"
          >
            <el-button @click="cancel">取消</el-button>
            <el-button type="primary" @click="handleQuery">确认</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-dialog>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-search"
          size="mini"
          @click="handleSearch"
          >搜索</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-success"
          size="mini"
          :disabled="multiple"
          @click="handleCheck"
          v-hasPermi="['purchase:csm:check']"
        >
          审核
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-back"
          size="mini"
          :disabled="multiple"
          @click="handleBack"
          v-hasPermi="['purchase:csm:rollbackCsm']"
        >
          撤回
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['purchase:csm:export']"
        >
          导出
        </el-button>
      </el-col>
      <HdTagGroup :show="['tijiao', 'shenhe']" />
    </el-row>

    <el-table
      highlight-current-row
      v-loading="loading"
      :data="csmList"
      border
      stripe
      height="calc(50% + 80px)"
      @row-click="clickListFile"
      :row-style="{ padding: '0px' }"
      :cell-style="iCellStyle"
      :header-row-style="{ padding: '2px' }"
      @scrollBottom="load"
      :header-cell-style="{ 'text-align': 'center', padding: '2px' }"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="#" type="index" width="40" align="center" />
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="厂商代码"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="csmCsdm"
      />
      <el-table-column
        label="厂商名称"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="csmCsmc"
      />
      <el-table-column label="有效标识" align="center" width="100">
        <template #default="scope">
          <el-switch
            v-model="scope.row.csmFlag"
            active-value="0"
            inactive-value="1"
            @change="handleStatusChange(scope.row)"
          ></el-switch>
        </template>
      </el-table-column>
      <el-table-column
        label="备注"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="remark"
      />
      <el-table-column
        label="建立人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="createBy"
      />
      <el-table-column
        label="建立时间"
        :show-overflow-tooltip="true"
        align="center"
        prop="createTime"
        width="150"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="更新人员"
        :show-overflow-tooltip="true"
        width="80"
        align="center"
        prop="updateBy"
      />
      <el-table-column
        label="更新时间"
        :show-overflow-tooltip="true"
        align="center"
        prop="updateTime"
        width="150"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.updateTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="供货类型"
        :show-overflow-tooltip="true"
        width="80"
        align="center"
        prop="csmType"
      >
        <template #default="scope">
          <dict-tag :options="csmTypeOptions" :value="scope.row.csmType" />
        </template>
      </el-table-column>
      <el-table-column
        label="产品名称"
        :show-overflow-tooltip="true"
        width="120"
        prop="csmCpmc"
      />
      <el-table-column
        label="公司名称"
        :show-overflow-tooltip="true"
        width="200"
        prop="csmGsmc"
      />
      <el-table-column
        label="开户行"
        :show-overflow-tooltip="true"
        width="250"
        prop="csmBank"
      />
      <el-table-column
        label="银行账户"
        :show-overflow-tooltip="true"
        width="180"
        prop="csmAccid"
      />
      <el-table-column
        label="联系人员"
        :show-overflow-tooltip="true"
        width="80"
        align="center"
        prop="csmLxry"
      />
      <el-table-column
        label="联系电话"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="csmPhone"
      />
      <el-table-column
        label="传真"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="csmFax"
      />
      <el-table-column
        label="公司法人"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="csmGsfr"
      />
      <el-table-column
        label="付款类型"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="csmFktype"
      >
        <template #default="scope">
          <dict-tag :options="csmFktypeOptions" :value="scope.row.csmFktype" />
        </template>
      </el-table-column>
      <el-table-column
        label="付款周期"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="csmFkzq"
      />
      <el-table-column
        label="合同开始"
        :show-overflow-tooltip="true"
        align="center"
        prop="csmKsrq"
        width="180"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.csmKsrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="合同结束"
        :show-overflow-tooltip="true"
        align="center"
        prop="csmJsrq"
        width="180"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.csmJsrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="地址"
        :show-overflow-tooltip="true"
        width="350"
        prop="csmAddr"
      />
      <!-- <el-table-column label="操作" align="center" fixed="right" width="180" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button type="text" icon="el-icon-edit" size="mini" @click="upLoad(scope.row)" v-hasPermi="['project:csm:upload']">上传</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['purchase:csm:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['purchase:csm:remove']">
            删除
          </el-button>
        </template>
      </el-table-column> -->
    </el-table>

    <el-table
      border
      stripe
      highlight-current-row
      height="calc(50% - 120px)"
      :row-style="{ padding: '0px' }"
      :cell-style="{ padding: '0px 0' }"
      :header-row-style="{ padding: '2px 0' }"
      :header-cell-style="{ 'text-align': 'center', padding: '2px' }"
      :data="csmFileList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="#" type="index" width="40" align="center" />
      <el-table-column label="文件编号" align="center" prop="docDjbh" />
      <el-table-column label="厂商代码" align="center" prop="docMjbh" />
      <el-table-column label="文件名称" align="center" prop="docName" />
      <el-table-column label="备注" align="center" prop="docDesc" />
      <el-table-column label="建立人员" align="center" prop="createBy" />
      <el-table-column label="建立日期" align="center" prop="createTime" />
      <el-table-column label="操作" width="120" fixed="left" align="center">
        <template #default="scope">
          <el-button size="mini" type="text" @click="handleImgLook(scope.row)"
            >查看</el-button
          >
          <el-button
            size="mini"
            type="text"
            v-hasPermi="['purchase:csm:remove']"
            @click="handleFileDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 上传对话框 -->
    <el-dialog
      :title="title"
      v-model="openStr"
      :close-on-click-modal="false"
      draggable
      width="500px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="厂商代码">
          <el-input v-model="form.csmCsdm" disabled />
        </el-form-item>
        <el-form-item label="厂商名称">
          <el-input v-model="form.csmCsmc" disabled />
        </el-form-item>
        <el-form-item label="文件名称" prop="csmFile">
          <el-input
            v-model="form.csmFile"
            placeholder="请输入文件名称"
            @input="upLoadFile"
          />
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="form.csmDesc" placeholder="请输入备注名称" />
        </el-form-item>
      </el-form>
      <div
        slot="footer"
        class="dialog-footer"
        style="display: flex; flex-direction: row-reverse"
      >
        <el-button @click="cancelOpenStr">取 消</el-button>
        <el-upload
          action="#"
          :http-request="requestUpload"
          :show-file-list="false"
          :before-upload="beforeUpload"
          :disabled="upLoading"
        >
          <el-button :disabled="upLoading">
            上传
            <i class="el-icon-upload el-icon--right"></i>
          </el-button>
        </el-upload>
      </div>
    </el-dialog>
    <!-- 添加或修改供应商资料对话框 -->
    <el-dialog
      :title="title"
      v-model="open"
      :close-on-click-modal="false"
      draggable
      width="800px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-col :span="12">
          <el-form-item label="厂商代码" prop="csmCsdm">
            <el-input v-model="form.csmCsdm" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="厂商名称" prop="csmCsmc">
            <el-input v-model="form.csmCsmc" placeholder="请输入厂商名称" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="付款类型" prop="csmFktype">
            <el-select
              v-model="form.csmFktype"
              style="width: 300px"
              placeholder="请选择付款类型"
            >
              <el-option
                v-for="dict in csmFktypeOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="供货类型" prop="csmType">
            <el-select
              v-model="form.csmType"
              style="width: 300px"
              placeholder="请选择供货类型"
            >
              <el-option
                v-for="dict in csmTypeOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="产品名称" prop="csmCpmc">
            <el-input v-model="form.csmCpmc" placeholder="请输入产品名称" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="公司名称" prop="csmGsmc">
            <el-input v-model="form.csmGsmc" placeholder="请输入公司名称" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="开户行" prop="csmBank">
            <el-input v-model="form.csmBank" placeholder="请输入开户行" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="银行账户" prop="csmAccid">
            <el-input v-model="form.csmAccid" placeholder="请输入银行账户" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="联系人员" prop="csmLxry">
            <el-input v-model="form.csmLxry" placeholder="请输入联系人员" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="联系电话" prop="csmPhone">
            <el-input v-model="form.csmPhone" placeholder="请输入联系电话" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="传真" prop="csmFax">
            <el-input v-model="form.csmFax" placeholder="请输入传真" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="公司法人" prop="csmGsfr">
            <el-input v-model="form.csmGsfr" placeholder="请输入公司法人" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="合同开始" prop="csmKsrq">
            <el-date-picker
              size="small"
              v-model="form.csmKsrq"
              type="date"
              :clearable="false"
              style="width: 300px"
              value-format="yyyy-MM-dd"
              placeholder="选择合同开始"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="合同结束" prop="csmJsrq">
            <el-date-picker
              size="small"
              v-model="form.csmJsrq"
              type="date"
              :clearable="false"
              style="width: 300px"
              value-format="yyyy-MM-dd"
              placeholder="选择合同结束"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="备注" prop="remark">
            <el-input v-model="form.remark" placeholder="请输入备注" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="付款周期" prop="csmFkzq">
            <el-input v-model="form.csmFkzq" placeholder="请输入付款周期" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="地址" prop="csmAddr">
            <el-input v-model="form.csmAddr" placeholder="请输入地址" />
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 撤回 -->
    <el-dialog
      v-model="check_back"
      draggable
      width="300"
      title="确认撤回？"
    >
      <div style="text-align: center">
        <p>撤回理由</p>
        <el-input v-model="reson" style="width: 75%" />
      </div>
      <div slot="footer">
        <el-button type="danger" @click="rollbackCsm">撤回</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  addCsm,
  checkCsm,
  delCsm,
  exportCsm,
  getCsm,
  listCsm,
  listFile,
  updateCsm,
  updateFlag,
  rollbackCsm,
} from "@/api/purchase/csm";
import { uploadMjm } from "@/api/project/mjmMstr";
import { delDocList } from "@/api/project/docList";

export default {
  name: "Csm",
  data() {
    return {
      upLoading: true,
      // 遮罩层
      loading: true,
      tableH: 1,
      tableHChild: 1,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],

      //存储当前厂商名
      csmNames: [],

      //保存当前厂商属性
      csmData: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 供应商资料表格数据
      csmList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openStr: false,
      // 有效标识字典
      csmFlagOptions: [],
      csmFileList: [],
      // 供货类型字典
      queryTrees: {
        mjmJzid: null,
        mjmKhid: null,
      },
      csmTypeOptions: [],
      // 付款类型字典
      csmFktypeOptions: [],
      openSearch: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        csmCsdm: null,
        csmType: null,
        csmCpmc: null,
        csmCsmc: null,
        csmGsmc: null,
        csmZtbz: "1",
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        csmCsmc: [
          { required: true, message: "厂商名称不能为空", trigger: "blur" },
        ],
        csmFlag: [
          { required: true, message: "有效标识不能为空", trigger: "blur" },
        ],
        csmType: [
          { required: true, message: "供货类型不能为空", trigger: "change" },
        ],
        // csmFile: [{ required: true, message: '文件名称不能为空', trigger: 'change' }],
      },
      check_back: false,
      reson: "",
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_normal_disable").then((response) => {
      this.csmFlagOptions = response.data;
    });
    this.getDicts("purchase_supply_style").then((response) => {
      this.csmTypeOptions = response.data;
    });
    this.getDicts("payment_way").then((response) => {
      this.csmFktypeOptions = response.data;
    });
  },
  methods: {
    requestUpload() {},
    // 上传预处理
    beforeUpload(file) {
      const reader = new FileReader();
      reader.readAsDataURL(file);
      reader.onload = () => {
        this.upDateContainer = reader.result;
        let formData = new FormData();
        formData.append("docType", "E");
        formData.append("mjbh", this.form.csmCsdm);
        formData.append("fileName", this.form.csmFile);
        formData.append("desc", this.form.csmDesc);
        formData.append("file", file);
        uploadMjm(formData).then((response) => {
          this.mjmFile(this.form.csmCsdm);
          this.$message.success("文件上传成功");
          this.openStr = false;
          this.upLoading = true;
        });
      };
    },
    //删除子项
    handleFileDelete(row) {
      this.$confirm(
        '是否确认删除文件编号为"' + row.docDjbh + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          console.log(row.docDjbh);
          return delDocList(row.docDjbh);
        })
        .then(() => {
          this.mjmFile(this.form.csmCsdm);
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    clickListFile(row) {
      this.csmData = row;
      this.mjmFile(row.csmCsdm);
    },
    /** 得到文件 */
    mjmFile(query) {
      listFile(query).then((response) => {
        this.csmFileList = response.data;
      });
    },

    upLoadFile(a) {
      if (a) {
        this.upLoading = false;
      } else {
        this.upLoading = true;
      }
    },
    /** 查询供应商资料列表 */
    getList(row) {
      this.loading = true;
      this.tableH = document.body.clientHeight / 2 - 20;
      this.tableHChild = document.body.clientHeight / 2 - 200;
      this.queryParams.pageNum = 1;
      listCsm(this.queryParams).then((response) => {
        this.csmList = [];
        this.csmList = this.csmList.concat(response.rows);
        this.total = response.total;
        this.loading = false;
        this.csmFileList = [];
        if (row != null) {
          this.clickListFile(row);
        } else if (this.csmList != null && this.csmList.length > 0) {
          this.clickListFile(this.csmList[0]);
        }
      });
    },
    load() {
      if (
        this.queryParams.pageNum <
        Math.ceil(this.total / this.queryParams.pageSize)
      ) {
        // this.$message.success("加载下一页");
        this.queryParams.pageSize = 20;
        this.queryParams.pageNum++;
        listCsm(this.queryParams).then((response) => {
          this.csmList = this.csmList.concat(response.rows);
          this.total = response.total;
          this.loading = false;
          this.csmFileList = [];
        });
      }
      return 0;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
      this.openSearch = false;
    },

    cancelOpenStr() {
      this.openStr = false;
      this.reset();
    },
    handleSearch() {
      this.reset();
      this.title = "查询供应商资料";
      this.openSearch = true;
    },
    // 表单重置
    reset() {
      this.form = {
        csmId: null,
        csmCsdm: null,
        csmCsmc: null,
        csmFlag: "0",
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        csmType: null,
        csmCpmc: null,
        csmGsmc: null,
        csmBank: null,
        csmAccid: null,
        csmLxry: null,
        csmPhone: null,
        csmFax: null,
        csmGsfr: null,
        csmFktype: null,
        csmFkzq: null,
        csmFile: null,
        csmKsrq: null,
        csmJsrq: null,
        csmAddr: null,
        csmDesc: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
      this.openSearch = false;
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.csmId);
      this.csmNames = selection.map((item) => item.csmCsdm);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加供应商资料";
    },
    //上传
    upLoad(row) {
      this.reset();
      this.form.csmCsdm = row.csmCsdm;
      this.form.csmCsmc = row.csmCsmc;
      this.openStr = true;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const csmId = row.csmId || this.ids;
      getCsm(csmId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改供应商资料";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.csmId != null) {
            updateCsm(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList(this.csmData);
            });
          } else {
            this.form.csmZtbz = "1";
            addCsm(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    pageChange(page) {
      this.queryParams.pageNum = page;
      this.getList();
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const csmIds = row.csmId || this.ids;
      const csmNames = row.csmCsdm || this.csmNames;
      this.$confirm(
        '是否确认删除供应商资料编号为"' + csmNames + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          return delCsm(csmIds);
        })
        .then(() => {
          this.queryParams.pageNum = 1;
          this.csmList = [];
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有供应商资料数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          return exportCsm(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
    handleImgLook(row) {
      let files = process.env.VUE_APP_BASE_API + row.docPath;
      window.open(files);
    },
    // 角色状态修改
    handleStatusChange(row) {
      let text = row.csmFlag === "0" ? "启用" : "停用";
      this.$confirm(
        '确认要"' + text + '"【' + row.csmCsmc + "】供应商吗?",
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return updateFlag({ csmId: row.csmId, csmFlag: row.csmFlag });
        })
        .then(() => {
          this.msgSuccess(text + "成功");
        })
        .catch(function () {
          row.csmFlag = row.csmFlag === "0" ? "1" : "0";
        });
    },
    /** 审核按钮操作 */
    handleCheck() {
      const lqmIds = this.ids;

      this.$confirm("确认要将选中单据通过审核?", "确认审核", {
        confirmButtonText: "审核",
        cancelButtonText: "取消",
        type: "info",
      })
        .then(function () {
          return checkCsm(lqmIds);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("审核成功");
        });
    },
    /** 撤销按钮操作 */
    handleBack() {
      if (!this.csmData.csmZtbz == 2) {
        this.msgError("请选择单据状态:【审核】的单据");
        return;
      }
      this.check_back = true;
    },
    rollbackCsm() {
      rollbackCsm({ csmId: this.csmData.csmId, csmDesc: this.reson }).then(
        (res) => {
          this.msgSuccess("撤回成功");
          this.check_back = false;
          this.getList();
        }
      );
    },
    /** 颜色事件 */ iCellStyle: function ({ row }) {
      if (row.csmZtbz == "1") {
        return "color:#0fac09";
      }
      //审核
      if (row.csmZtbz == "2") {
        return "color:#0323af";
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.el-pagination__jump {
  margin-left: 0;
}
</style>
